package com.tarena.action;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tarena.bo.EmpDao;
import com.tarena.controller.Action;
import com.tarena.util.FormUtils;
import com.tarena.vo.Dept;
import com.tarena.vo.Emp;

/**
 * 
 * @添加员工类
 * @author Wangpeihu
 * @since 31/12/2009
 * @Team [Never give up]
 */
public class AddEmpAction extends Action {
	private EmpDao ed = new EmpDao();

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		try {
			request.setCharacterEncoding("utf-8");
			Emp emp = new Emp();
			Dept dept = new Dept();
			emp.setDept(dept);
			FormUtils.populate(emp, request);
			if ("" != emp.getName().trim() && null != emp.getHireDate()) {
				ed.addEmp(emp);
			}
			response.sendRedirect("emp_list");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
